package shuffe;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;

public class Cards {

    public static final String[] suits = {"♥","♠","♣","♦"};

    public List<Card> buycard(){
        List<Card> cardList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j < 14; j++) {
                int num = j;
                String suit = suits[i];
                Card card = new Card(num,suit);
                cardList.add(card);
            }
        }
        return cardList;
    }


    public void shuffle(List<Card> cardList){
        Random random = new Random();
        for (int i = cardList.size()-1; i > 0 ; i--) {
            int randonIndex = random.nextInt(i);
            swap(cardList, i, randonIndex);
        }
    }

    private void swap(List<Card> cardList , int i , int j){
        Card temp = cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,temp);
    }

    public List<List<Card>> drawCard(List<Card> cardList){
            List<Card> hand1 = new ArrayList<>();
            List<Card> hand2 = new ArrayList<>();
            List<Card> hand3 = new ArrayList<>();

            List<List<Card>> hands = new ArrayList<>();
            hands.add(hand1);
            hands.add(hand2);
            hands.add(hand3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cardList.removeFirst();
                List<Card> tmpHand = hands.get(j);
                tmpHand.add(card);
            }
        }
        return hands;

    }

    public void sort(List<List<Card>> hand){
        List<List<Card>> hands = new ArrayList<>();
    }

}
